package com.lanou.timeline.comment.service.impl;

import com.lanou.timeline.comment.entity.TimelineComment;
import com.lanou.timeline.comment.mapper.TimelineCommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TimelineCommentServiceImpl {
    @Autowired
    private TimelineCommentMapper timelineCommentMapper;
    public void publishComment(TimelineComment timelineComment) {
        long addtime = (new Date().getTime())/1000;
        timelineComment.setAddtime(addtime);
        timelineCommentMapper.publishComment(timelineComment);
    }

    public List<TimelineComment> showComment(String timelineId) {
        return timelineCommentMapper.showComment(timelineId);
    }

    public void reportComment(String tagCommentId) {
        int reprotCount = timelineCommentMapper.selectReoprt(tagCommentId) +1;
        timelineCommentMapper.reportComment(tagCommentId,reprotCount);

    }

    public void updateIsgood(String tagCommentId, int uid) {
        if (timelineCommentMapper.commentIsgood(tagCommentId,uid) == 1){
            timelineCommentMapper.deleteIsgood(tagCommentId,uid);
        }else {
            timelineCommentMapper.insertIsgood(tagCommentId,uid);
        }
    }

    public void deleteComment(String tagCommentId, int uid) {
        timelineCommentMapper.deleteComment(tagCommentId,uid);
    }
}
